package sk.fei.vrml.objects;

import sk.fei.vrml.main.Constants;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;



/**
 * VrmlCone class represents VRML object Cone. Properties are bottom radius,
 * height, and two boolean values side and bottom. If side is true, than the body
 * of cone is drawn. When bottom is true, than the bottom of cone is drawn.
 * 
 * http://www.lighthouse3d.com/vrml/tutorial/index.shtml?cone
 * 
 * Cone {
 *		field SFFloat bottomRadius 1
 *		field SFFloat height 2
 *		field SFBool side TRUE
 *		field SFBool bottom TRUE 
 *	}
 * 
 * @author anubis
 * 
 */
public class VrmlCone extends VrmlObject {
	private float bottomRadius;
	private float height;
	private boolean side;
	private boolean bottom;

	public VrmlCone(float bottomRadius,float height,boolean side,boolean bottom) {
		this.bottomRadius = bottomRadius;
		this.height = height;
		this.side = side;
		this.bottom = bottom;
		this.type = Constants.Cone;
	}
	
	public void draw(GLAutoDrawable GLAutoDrawable,VrmlAppearance appearance) {
		GL gl = GLAutoDrawable.getGL();
		GLU glu = new GLU();
        final int slices = 16;
        final int stacks = 16;
        // otocenie aby sa nedaval nalezato a posunutie aby sa tocil okolo svojho stredu
        gl.glRotated(90, 1, 0 ,0);
        gl.glTranslatef(0, 0, -height/2);
        // vykreslenie obalu
        if (side){
        	//gl.glColor3f(0.3f, 0.5f, 1f);
            GLUquadric cone = glu.gluNewQuadric();
            appearance.applyObjectMaterial(GLAutoDrawable);
            appearance.applyTexture(GLAutoDrawable, cone);
        	glu.gluCylinder(cone, 0, bottomRadius, height, slices, stacks);
        	glu.gluDeleteQuadric(cone);
        }
        // vykreslenie spodneho uzaveru
        if (bottom){
        	GLUquadric bottomDisk = glu.gluNewQuadric();
        	glu.gluQuadricOrientation 	(	bottomDisk , GLU.GLU_INSIDE );
        	appearance.applyObjectMaterial(GLAutoDrawable);
            appearance.applyTexture(GLAutoDrawable, bottomDisk);
            gl.glTranslatef(0, 0, height);
           // gl.glColor3f(0.6f, 0.2f, 1f);
        	glu.gluDisk(bottomDisk, 0, bottomRadius, slices, stacks);
        	  gl.glTranslatef(0, 0, -height);
            glu.gluDeleteQuadric(bottomDisk);
        }
        if(appearance != null ) {
        	if (appearance.isTextureSeted()) gl.glDisable(GL.GL_TEXTURE_2D);
        }
	}

	public String toString() {
		return "Cone";
	}
	
	public float getBottomRadius() {
		return bottomRadius;
	}
	
	public void setBottomRadius(float radius){
		this.bottomRadius = radius;
	}
	
	public float getHeight() {
		return height;
	}
	
	public boolean getSide() {
		return side;
	}
	
	public boolean getBottom() {
		return bottom;
	}
	
	public void setSide(Boolean bool){
		this.side = bool;
	}
	
	public void setBottom(Boolean bool){
		this.bottom = bool;
	}
	
	public void setHeight(float height) {
		this.height = height;
	}
	
}
